package com.yssoft.controller.supervise;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yssoft.controller.BaseController;
import com.yssoft.entity.core.TProductClassify;
import com.yssoft.entity.supplier.BillCountCustom;
import com.yssoft.service.core.AreaService;
import com.yssoft.service.core.ProductClassifyService;
import com.yssoft.service.supervise.BillCountService;
/**
 * 销售订单统计
 * @author ljy
 *
 */
@RequestMapping("/supplier/billCount")
@Controller
public class BillCountController extends BaseController{
	private static Logger logger=Logger.getLogger(BillCountController.class);
	@Resource
	private BillCountService billCountService;
	@Autowired
	private ProductClassifyService productClassifyService;
	@Resource
    private AreaService areaService;
	/**
	 * @方法名称: list
	 * @功能描述: 跳转到销售统计列表页
	 * @作者: ljy
	 * @创建时间: 2018年6月10日 上午9:53:19
	 * @param model
	 * @return String
	 */
	@RequestMapping(value = "/list")
	public String list(Model model){
	 
		List<Map<String, Object>> jsonArray = productClassifyService.queryProClaTree();
        String areaTree = areaService.queryAreaTree();
        model.addAttribute("mJson", JSONArray.toJSON(jsonArray));
        model.addAttribute("areaTree", areaTree);
		return "supervise/sales/billList";
	}
	
	@ResponseBody
	@RequestMapping(value = "billPage")
	public JSONObject billPage(@RequestParam(name = "page",defaultValue = "0") int page ,
							   @RequestParam(name = "limit",defaultValue = "10") int limit, 
							   BillCountCustom  custom  ) throws IllegalAccessException, ClassNotFoundException{
		logger.debug( "json:"+custom.getJsonParam()  );
        JSONObject jsonObject = billCountService.queryBillPage(page, limit, custom);
        return jsonObject;
    }
	/**
	 * 
	 * @param 跳到选择企业页面
	 * @return
	 */
	@RequestMapping(value = "/selectEnterpriseList")
	public String selectEnterpriseList(Model model){
		return "supervise/sales/selectEnterprise";
	}
	/**
	 * 查询生产企业列表
	 * @param page
	 * @param limit
	 * @param sourceName
	 * @param pType
	 * @return
	 * @throws ClassNotFoundException 
	 * @throws IllegalAccessException 
	 */
	@ResponseBody
	@RequestMapping(value = "enterprisePage")
	public JSONObject enterprisePage(@RequestParam(name = "page",defaultValue = "0") int page,
    		@RequestParam(name = "limit",defaultValue = "10") int limit, String enterpriseName ) throws IllegalAccessException, ClassNotFoundException{
	    	JSONObject enterpriseList = billCountService.queryEnterprisePage(page, limit, enterpriseName);
		return enterpriseList;
	}
	
	/**
	 * @方法名称: toView
	 * @功能描述: 跳转到详细页面
	 * @作者: 洪丰
	 * @创建时间:2018年7月9日 下午3:28:58
	 * @param model
	 * @return String
	 */
	@RequestMapping(value = "/toView")
	public String toView(Model model,Integer id){
		BillCountCustom billMap = billCountService.querybillOne(id);
		model.addAttribute("billMap", billMap);
		return "supervise/sales/billView";
	}
}
